<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!-- 导入标签库 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <title>『自助物流系统』后台管理</title>
	<link rel="stylesheet" type="text/css" href="UI/users/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="UI/users/css/main.css"/>
    <link href="UI/users/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="UI/users/js/libs/modernizr.min.js"></script>
   	<script src="UI/users/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<s:if test="null==#session.account">
	<s:a href="login.action" align="center"><h2>您不能直接访问网站内部页面,请先登录!</h2></s:a>
</s:if>
<s:else>
	        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i>
            <span class="crumb-name">首页</span><span class="crumb-step">&gt;</span>
            <span class="crumb-name">商品管理</span>
            </div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="searchGoods" method="post">
                    <table class="search-tab">
                        <tr>
                            <th width="100">商品名称:</th>
                            <td><input class="common-text" placeholder="输入商品名称" name="goods.name" id="goods.name" type="text"></td>
                            <td><input class="btn btn-primary btn2" name="sub" value="查询" type="submit"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="goodsListForm" id="goodsListForm" method="post">
                <div class="result-title">
                    <div class="result-list">
                        <a href="preAddGood"><i class="icon-font"></i>新增商品</a>
<!--                         <a id="batchDel" name="batchDel" onClick="batchDeleteGoods()"><i class="icon-font"></i>批量删除</a>
                        <a id="updateGoods" name="updateGoods" onClick="updateGoodsSort()"><i class="icon-font"></i>更新排序</a> -->
                    </div>
                </div>
                <div class="result-content">
                    <table class="result-tab" width="100%">                  
                    <thead>
                        <tr>
               <!--              <th class="tc" width="5%"><input class="allChoose" name="goodsAllCheck" id="goodsAllCheck" type="checkbox"></th> -->
               
                            <th>商品名称</th>
                            <th>价格(￥)</th>
                            <th>类别</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
	                    <!-- here we user iterator to display all goods. -->
	                    <s:iterator value="goodsList" var="goods">
	                    	<tr>
		                        <td><s:property value="#goods.name"></s:property></td>
		                        <td><s:property value="#goods.price"></s:property></td>
		                        <td><s:property value="#goods.goodskind.name"></s:property></td>	
		                        <td>
		                        	<a href="preUpdateGood?id=<s:property value='#goods.id'/>">修改</a>
		                        	<a href="javascript:del(<s:property value='#goods.id'/>)">删除</a>
		                        </td>
	                    	</tr>
	                    </s:iterator>
                    </tbody> 
                    </table>
                    <div align="center" class="result-content">
			                    	<s:iterator value="pageBean">    
			                                <tr>    
			                                 <td colspan="4" align="center" bgcolor="#5BA8DE">
			                                 <br>    
			                                 共<strong><s:property value="allRow"/></strong>条记录        
			                                 共<strong><s:property value="totalPage"/></strong>页        
			                                 当前第<strong><s:property value="currentPage"/></strong>页<br>    
			                                
			                                 <s:if test="%{currentPage == 1}">    
			                                   第一页  上一页    
			                                 </s:if>    
			                                 <!-- currentPage为当前页 -->    
			                                 <s:else>    
			                                   <a href="goodsList.action?page=1">第一页</a>    
			                                   <a href="goodsList.action?page=<s:property value="%{currentPage-1}"/>">上一页</a>    
			                                 </s:else>    
			                                
			                                 <s:if test="%{currentPage != totalPage}">    
			                                 <a href="goodsList.action?page=<s:property value="%{currentPage+1}"/>">下一页</a>    
			                                 <a href="goodsList.action?page=<s:property value="totalPage"/>">最后一页</a>    
			                                 </s:if>    
			                                
			                                 <s:else>    
			                                 下一页  最后一页    
			                                 </s:else>    
			                                 </td>    
			                                </tr>    
			                        </s:iterator> 
                    </div>

                </div>
            </form>
        </div>
 </s:else>   
<script type="text/javascript">
    var deleteGoodId;
    
    //首先得到勾选的项
    function chosedDeleteGoodsId(){
    	var count=0;
    	var goodsCheckBox=document.getElementsByName("goodsCheck");
    	for(i=0;i<goodsCheckBox.length;i++){
    		if(goodsCheckBox[i].checked){
    			count++
    		}
    	}
    	return count;
    }
    
    //批处理删除商品
    function batchDeleteGoods(){
    	if(chosedDeleteGoodsId()==0){
    		alert("请选择要批量删除的商品！");
    		return;
    	}
    	if(confirm("确定要删除所选商品吗？")){
    		var batchDeleteAllGoods=document.getElementById("");
    		//具体的action
    		//
    		batchDeleteAllGoods.submit();
    	}
    	
    }
    
    //更新商品的排序
    function updateGoodsSort(){
    	
    }
    
    //得到要删除的商品ID
   	function selectedDeleteGood(selectedGoodId){
   		deleteGoodId=selectedGoodId;
    }
    
    //单一的删除商品
    function singleDeleteGood(){
    	//实现删除单一的商品
    }
    
    //单独的删除一个商品
    function del(goodId){
    	if(confirm("确定删除此商品?")){
    		window.location.href="deleteGood?id="+goodId;
 //   		window.location.href="deleteGood?";
    	}
    	
    }
</script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
	//获取goodskind
	$.post("listGoodskind.action",function(data){      //data代表服务器端传来的数据
		var jsonObj=eval("("+data+")");                    //封装服务器数据为json对象
		for(var i=0;i<jsonObj.length;i++){
			var $option=$("<option></option>");
			$option.attr("value",jsonObj[i].id);
			$option.text(jsonObj[i].name);
			$("#kind").append($option);
		}
	});
});
</script>
</body>
</html>